export { }
// 类型
const num: number = 1
const str: string = '123'
const bool: boolean = true
const arr: number[] = [1, 2, 3, 4]
const arr1: [boolean, number] = [true, 1231231]
// null undefined never any unknown enum

// 接口
interface ObjState {
	// 必须属性
	name: string
	age: number
	// 可选属性
	sex?: "男" | "女"
	// 只读属性
	readonly code: string
	// 其他属性
	[propNmae: string]: any
}

const o: ObjState = {
	name: '张三',
	age: 18,
	code: '1231231231',
	qwe: '蔷薇蔷薇'
}
o.sex = '男'
const o1: ObjState = {
	name: '李四',
	age: 20,
	sex: '女',
	code: '12312313',
	rthrg: 12312313
}

// 类
class Person {
	name: string
	age: number
	constructor(name: string, age: number) {
		this.name = name
		this.age = age
	}

	sayName() {
		console.log(`我是${this.name}, 今年${this.age}岁了`)
	}
}
const p = new Person('张三', 18)
p.sayName()
// console.log(p);

// 泛型

function id<T>(x: T) {
	return x
}

id<number>(1231231)

id<string>("1231231231")

id<boolean>(true)


// 6.装一个泛型类GetMax;
class GetMax<T> {
	findMax(arr: number[]) {
		const value = Math.max(...arr)
		const index = arr.indexOf(value)
		return {
			value,
			index
		}
	}
}

const test = new GetMax()
const s = test.findMax([1, 2, 3, 4, 5, 4, 3, 2, 1])


function findLongestWord(str: string): string {
	// "I am a teache werwerwerwer werwerwerwe werwerwerwrwerwerwerwerwerew"
	const arr = str.split(' ')
	// ["I, am, a, teache, werwerwerwer, werwerwerwe, werwerwerwrwerwerwerwerwerew"]
	const arrLen = arr.map(v => v.length)
	// [1, 2, 1, 6, 10, 10, 20]
	const o = test.findMax(arrLen)
	// {  value, index  }
	return arr[o.index]
}

console.log(findLongestWord("I am aaaaaaaaaaaa teacher"))



